const router = require("koa-router")();
const jsonwebtoken = require("jsonwebtoken");
const path = require("path");
const { getExcelObjs } = require("../utils/uploadExcelSrv");

// router.post('/api/uploadFile', async (ctx, next) => {
//   const result = await getExcelObjs(ctx)
//   console.log('result, ', result)
//   ctx.body = {
//     code: 0,
//     msg: 'success',
//     result
//   }
// })

router.post("/api/test", async (ctx, next) => {
  ctx.body = {
    code: 0,
    msg: "success",
  };
});

router.post("/api/uploadImg", async (ctx, next) => {
  console.log("ctx.request.file:", ctx.request.files.file);
  // http://localhost:3000/
  // uploads/1.jpeg
  const file = ctx.request.files.file;
  const basename = path.basename(file.path);
  ctx.body = {
    code: 0,
    msg: "success",
    filePath: ctx.origin + "/uploads/" + basename,
  };
});

module.exports = router;
